#include "frmtechcrststu.h"
#include "ui_frmtechcrststu.h"

FrmTechCrstStu::FrmTechCrstStu(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FrmTechCrstStu)
{
    ui->setupUi(this);
    this->initForm();
}

FrmTechCrstStu::~FrmTechCrstStu()
{
    delete ui;
}

void FrmTechCrstStu::initForm()
{
    model=new QStandardItemModel(this);
    model->appendRow(new QStandardItem("刘晓明"));
    model->appendRow(new QStandardItem("胡大志"));
    model->appendRow(new QStandardItem("陈阿斗"));

    ui->lstStuAll->setModel(model);

    connect(ui->lstStuAll,SIGNAL(clicked(QModelIndex)),this,SLOT(lstItemClick(QModelIndex)));

    filterModel=new QStandardItemModel(this);
    ui->lstStuSelect->setModel(filterModel);
}

void FrmTechCrstStu::lstItemClick(QModelIndex index)
{

}

void FrmTechCrstStu::on_btnPush_clicked()
{
    QItemSelectionModel *selItem=ui->lstStuAll->selectionModel();
    if(!selItem)
    {
        return;
    }
    QModelIndexList indexlst=selItem->selectedIndexes();
    if(indexlst.count()>0)
    {
        foreach (QModelIndex mitem, indexlst) {
            filterModel->appendRow(new QStandardItem(mitem.data().toString()));
            ui->lstStuAll->model()->removeRow(mitem.row());
        }
    }

}

void FrmTechCrstStu::on_btnRemove_clicked()
{
    QItemSelectionModel *selItem=ui->lstStuSelect->selectionModel();
    if(!selItem)
        return;

    QModelIndexList indexlst=selItem->selectedIndexes();
    if(indexlst.count()>0)
    {
        foreach (QModelIndex mitem, indexlst) {
            model->appendRow(new QStandardItem(mitem.data().toString()));
            ui->lstStuSelect->model()->removeRow(mitem.row());
        }
    }

}

